import mitt from 'mitt';
import { onMounted, onUnmounted } from 'vue';

type Events = {
  RESUME_UPDATE: any; // 更新简历
  ANNOUNCEMENT_UPDATE: any;

  // 在线聊天
  'mitt:CHAT_ACCEPT_NEW_MSG': any;
  'mitt:CHAT_SEND_NEW_MSG': any;
  'mitt:CHAT_MAKE_MSG_READ': any;
};

export const emitter = mitt();

export function useMitt(event: keyof Events, callback: any) {
  onMounted(() => {
    emitter.on(event, callback);
  });
  onUnmounted(() => {
    emitter.off(event, callback);
  });
}
